home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 4 / MacMania 4.toast / / Demo's / Igor Demo Pro / 3 PutContentsIn Igor Pro Folder / Technical Notes / Igor Tech Notes / TN033 Confidence Bands / Conf Bands TEXT < prev    next >
Text File  |  1993-05-07  |  2KB  |  85 lines

  1.  
  2. | Returns area of Student's distribution function from -t,t given v degrees of freedom
  3. | Same as Abramowitz and Stegun, Page 990. Note that this includes both
  4. | tails.
  5. |
  6. Function StudentA(t,v)
  7.     Variable t,v        | Student's t, degreees of freedom v
  8.     
  9.     return 1-betai(v/2, .5, v/(v+t^2))
  10. End
  11.  
  12.  
  13. | Returns that t that gives the A given v degrees of freedom
  14. | Doesn't handle ridiculous values like 2 degrees of freedom and 0.99999
  15. |
  16. Function StudentT(A,v)
  17.     Variable A,v            | A= probablility, v= degrees of freedom
  18.     
  19.     if( (A>1) %| (A<0) %| (v<0) )
  20.         return NaN
  21.     endif
  22.  
  23.     variable tl= 0, tu= 100        | lower and upper bounds
  24.     variable tm                    | midpoint
  25.  
  26.     do
  27.         if( tu-tl <= 0.000005 )    | assume A to 5 sig figs is good enough
  28.             break;
  29.         endif
  30.         tm= (tu+tl)/2
  31.         if( StudentA(tm,v) <  A )
  32.             tl= tm
  33.         else
  34.             tu= tm
  35.         endif
  36.     while(1)
  37.     return tl
  38. end
  39.  
  40. Macro AddPredictionInterval(ydata,xdata,conf,kind)
  41.     String ydata,xdata
  42.     Variable conf=95,kind=1
  43.     Prompt ydata,"Y Data",popup WaveList("*",";","")
  44.     Prompt xdata,"X Data",popup "_calculated_;"+WaveList("*",";","")
  45.     Prompt conf,"confidence, %"
  46.     Prompt kind,"confidence kind",popup "Of the true mean;Of future measurements"
  47.     
  48.     PauseUpdate; Silent 1
  49.     
  50.     kind= kind==2
  51.     String pconf= ydata+"_PC", nconf= ydata+"_NC"
  52.     if( kind )
  53.         pconf += "D"; nconf += "D"        | addition of D to suffex denotes conf of future data
  54.     endif
  55.     Duplicate $ydata,tmpxdata,tmpydata
  56.     if( CmpStr(xdata,"_calculated_") == 0 )
  57.         tmpxdata= x
  58.     else
  59.         tmpxdata= $xdata
  60.     endif
  61.     
  62.     Make/O/N=100 $pconf,$nconf
  63.     WaveStats/Q tmpxdata
  64.     SetScale x,V_min,V_max,"",$pconf,$nconf
  65.     CheckDisplayed $pconf
  66.     if( !V_Flag )
  67.         Append $pconf,$nconf
  68.     endif
  69.     
  70.     Variable XBar= V_Avg
  71.     tmpydata = (tmpydata- (K0+K1*tmpxdata))^2
  72.     WaveStats/Q tmpydata
  73.     Variable s2= V_Avg*V_npnts/(V_npnts-2)
  74.     KillWaves tmpydata
  75.     tmpxdata= (tmpxdata-XBar)^2
  76.     WaveStats/Q tmpxdata
  77.     Variable SSXM= V_Avg*V_npnts
  78.     KillWaves tmpxdata
  79.     Variable k= StudentT(conf/100,V_npnts-2)*sqrt(s2)
  80.     
  81.     $pconf= k*sqrt(kind + 1/V_npnts + (x-XBar)^2/SSXM)
  82.     $nconf= K0+K1*x-$pconf
  83.     $pconf += K0 + K1*x
  84. End
  85.